
cc.Class({
    extends: cc.Component,

    properties: {
        delay: 0,
    },
    onLoad() {
        this.ani = this.node.getComponent(cc.Animation);
        if (!this.ani) {
            cc.log("AniPlayer: cant find cc.Animation");
            this.destroy();
            return;
        }
    },

    start() {
        if (this.delay > 0) {
            this.node.runAction(cc.sequence( cc.delayTime(this.delay), cc.callFunc(
                function(){
                    this.ani.play()
                }.bind(this)
            )));
        }
    },
    aniDestroy : function() {
        this.node.destroy();
    },

    emitAniMsg : function( msg ) {
        cc.utils.msgHub.emit( cc.utils.macro.EVENTS.ANI_MSG, msg );
    },
    playBgm : function( name ) {
        cc.utils.soundMgr.playBgm( name );
    },
    stopBgm : function( name ) {
        cc.utils.soundMgr.stopBgm( name );
    },
    playBgmEx : function( name, loop, volDetail, isFade ) {
        cc.utils.soundMgr.playBgm( name, loop, volDetail, isFade );
    },
    stopBgmEx : function( name, isFade ) {
        cc.utils.soundMgr.stopBgm( name, isFade );
    },
    playSound : function( name ) {
        cc.utils.soundMgr.playSound( name );
    },
    playAni : function( name, additive ){
        try {
            var ani = this.getComponent( cc.Animation );
            if( additive ) {
                ani.playAdditive( name );
            }
            else {
                ani.play( name );
            }
        }catch(e) {}
    }
});